from __future__ import division
import os.path

import pygame

import objects, players, doors, items, blocks, monsters
import hints, teleports, walls, buttons, dangers

import tiles

names = {
	"player": players.Player,
	
	"hint": hints.Hint,
	
	"door": doors.Door,
	"chip door": doors.ChipDoor,
	"red door": doors.RedDoor,
	"blue door": doors.BlueDoor,
	"green door": doors.GreenDoor,
	"yellow door": doors.YellowDoor,
	
	"chip": items.Chip,
	"key": items.Key,
	"red key": items.RedKey,
	"blue key": items.BlueKey,
	"green key": items.GreenKey,
	"yellow key": items.YellowKey,
	
	"fire": dangers.Fire,	
	"bomb": dangers.Bomb,
	
	"teleport": teleports.Teleport,
		
	"block": blocks.Block,
	"recessed wall": walls.RecessedWall,
	"toggle wall": walls.ToggleWall,
	"dirt": walls.Dirt,
	
	"toggle button": buttons.ToggleButton,
		
	"fireball": monsters.Fireball,
	"ball": monsters.Ball,
	
	"chasm": tiles.Chasm,
	"wall": tiles.Wall,
	"floor": tiles.Floor,
	"gravel": tiles.Gravel,
	"ice": tiles.Ice,
	"force": tiles.Force,
	"water": tiles.Water,
	"exit": tiles.Exit,
	"mystery wall": tiles.MysteryWall,
}

Z_ORDER = [
	players.Player,
	
	monsters.Fireball,
	monsters.Ball,
	
	doors.Door,
	doors.ChipDoor,
	doors.RedDoor,
	doors.BlueDoor,
	doors.GreenDoor,
	doors.YellowDoor,
	
	blocks.Block,
	
	walls.RecessedWall,
	walls.ToggleWall,
	
	walls.Dirt,
	
	items.Chip,	
	items.Key,
	items.RedKey,
	items.BlueKey,
	items.GreenKey,
	items.YellowKey,

	buttons.ToggleButton,
	
	dangers.Fire,
	dangers.Bomb,
	
	teleports.Teleport,
	hints.Hint,
	
	tiles.Exit,
	tiles.Wall,
	tiles.MysteryWall,
	tiles.Water,
	tiles.Chasm,
	tiles.Floor,
	tiles.Gravel,
	tiles.Force,
]

def load_graphics(gfx_dir):
	for object in names.itervalues():
		path = os.path.join(gfx_dir, object.graphic)
		object.graphic = pygame.image.load(path)
		object._frames = object.graphic.get_height() // 32
	
def convert_graphics():
	for object in names.itervalues():
		object.graphic = object.graphic.convert_alpha()
